#include <xp/bas/locale.h>
#include <xp/bas/string.h>

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <wchar.h>

int xp_main ()
{
	xp_wchar_t buf[50];
	xp_size_t n;

	xp_setlocale ();

	{
		const xp_mchar_t* mstr = XP_MTEXT("abcdefg\xA4**");
		xp_wchar_t bufx[100];
		unsigned int i;

		printf ("---------------\n");
		for (i = 0; i < 10 && i < xp_countof(bufx); i++) {
			n = xp_mcstowcs (mstr, bufx, i);
			printf ("buf[%u] ", i);

			if (n == -1) printf ("** conversion error **\n");
			else { 
				printf ("%lu/%lu bytes  %lu/%lu characters [%ls]\n", 
					n, strlen(mstr), xp_strlen(bufx), xp_mcswclen(mstr), bufx);
			}
		}
	}

	{
		const xp_mchar_t* mstr = XP_MTEXT("\xEC\x9C\xA0\xEB\x8B\x88\xEC\xBD\x94\xEB\x93\x9C");
		xp_wchar_t bufx[100];
		unsigned int i;

		printf ("---------------\n");
		for (i = 0; i < 10 && i < xp_countof(bufx); i++) {
			n = xp_mcstowcs (mstr, bufx, i);
			printf ("buf[%u] ", i);

			if (n == -1) printf ("** conversion error **\n");
			else { 
				printf ("%lu/%lu bytes  %lu/%lu characters [%ls]\n", 
					n, strlen(mstr), xp_strlen(bufx), xp_mcswclen(mstr), bufx);
			}
		}
	}

/*
	{

		printf ("---------------\n");
		n = mbstowcs (buf, "abc\xA4", xp_countof(buf));
		if (n == -1) printf ("** conversion error **\n");
		else wprintf (L"%lu/%lu [%ls]\n", n, xp_mcswclen("abc\xA4"), buf);
	}

	{
		printf ("---------------\n");
		n = mbstowcs (buf, "this is so good", xp_countof(buf));
		if (n == -1) printf ("** conversion error **\n");
		else wprintf (L"%lu/%lu [%ls]\n", n, xp_mcswclen("this is so good"), buf);
	}

	{
		xp_wchar_t buf3[3];
		printf ("---------------\n");
		n = mbstowcs (buf3, "abcdefghijkl", xp_countof(buf3));
		if (n == -1) printf ("** conversion error **\n");
		else wprintf (L"%lu/%lu [%ls]\n", n, xp_mcswclen("abcdefghijkl"), buf3);
	}
*/

	return 0;

}

